package com.example.controller;


import com.entity.AjaxResult;
import com.example.entity.Student;
import com.example.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * t_student表控制层
 * @date : 2024-03-14 13:48:40
 */
@RestController
@RequestMapping("/student")
public class StudentController{
    @Resource
    private StudentService studentService;

    /** 
     * 通过ID查询单条数据 
     *
     * @param stuId 主键
     * @return 实例对象
     */
    @GetMapping("{stuId}")
    public AjaxResult queryById(@PathVariable String stuId){
        return AjaxResult.success(studentService.getById(stuId));
    }

    /** 
     * 分页查询
     *
     * @param student 筛选条件
     * @param page 当前页(从1开始)
     * @param pageSize 每页大小
     * @return 查询结果
     */
    @GetMapping("paginQuery")
    public AjaxResult paginQuery(Student student, int page, int pageSize){

        return AjaxResult.success();
    }

    /** 
     * 新增数据
     *
     * @param student 实例对象
     * @return 实例对象
     */
    @PostMapping("add")
    public AjaxResult add(@RequestBody Student student){
        return AjaxResult.success(studentService.save(student));
    }

    /** 
     * 更新数据
     *
     * @param student 实例对象
     * @return 实例对象
     */
    @PutMapping("update")
    public AjaxResult edit(@RequestBody Student student){
        return AjaxResult.success(studentService.updateById(student));
    }

    /** 
     * 通过主键删除数据
     *
     * @param stuId 主键
     * @return 是否成功
     */
    @DeleteMapping("delete")
    public AjaxResult deleteById(String stuId){
        return AjaxResult.success(studentService.removeById(stuId));
    }
}